package com.atguigu.lease.web.admin.controller.agreement;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.RoomInfo;
import com.atguigu.lease.model.entity.ViewAppointment;
import com.atguigu.lease.web.admin.dto.AppointmentSearchDto;
import com.atguigu.lease.web.admin.service.ViewAppointmentService;
import com.atguigu.lease.web.admin.vo.AppointmentInfoVo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping(value = "/admin/appointment")
@Tag(name = "看房预约管理模块")
public class AppointmentController {
    @Resource
    ViewAppointmentService viewAppointmentService;
    //updateStatusById?id=1&status=3
    @Operation(summary = "更新看房预约状态")
    @PostMapping("/updateStatusById")
    // 增删改 后端可以返回增删改后的对象，目的方便前端局部刷新
    public Result updateStatusById(@RequestParam("id")Long id ,
                                   @RequestParam("status")Integer status){
        return Result.build(viewAppointmentService.update(Wrappers.lambdaUpdate(ViewAppointment.class)
                .eq(ViewAppointment::getId , id)
                .set(ViewAppointment::getAppointmentStatus , status)
                .set(ViewAppointment::getUpdateTime, new Date())));
    }
    @Operation(summary = "条件分页查询看房预约列表")
    @GetMapping("/page")
    public Result<Page<AppointmentInfoVo>> page(AppointmentSearchDto searchDto){
        return Result.ok(viewAppointmentService.pageItem(searchDto));
    }


}
